//
//  KSNotHaveDataExistView.swift
//  Supermarket
//
//  Created by liuxm on 2017/10/11.
//  Copyright © 2017年 kushao. All rights reserved.
//

import UIKit

/// 加载数据为空显示
class KSNotHaveDataExistView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    private lazy var imageView: UIImageView = {
        let imageView = UIImageView()
        
        return imageView
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = NSTextAlignment.center;
        label.textColor = KSColor.kColor_9;
        label.font = UIFont.systemFont(ofSize: 15);
        
        return label
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.colorWithHexString(hex: "#f4f6f7")
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 初始化页面
    ///
    /// - Parameters:
    ///   - imageName: 图片名字
    ///   - content: 内容
    func initView(imageName: String, content: String) {
        let image = UIImage(named: imageName)
        self.imageView.image = image
        let width = self.frame.width
        self.imageView.frame = CGRect(x: (width - (image?.size.width)!/1.2)/2, y: 40, width: (image?.size.width)!/1.2, height: (image?.size.height)!/1.2)
        self.addSubview(self.imageView)
        
        self.contentLabel.frame = CGRect(x: 0, y: self.imageView.frame.origin.y + self.imageView.frame.size.height + 15, width: width, height: 15)
        self.contentLabel.text = content
        self.addSubview(self.contentLabel)
    }
    
    /// 更新页面数据
    ///
    /// - Parameters:
    ///   - imageName: 图片名字
    ///   - content: 内容
    func updateView(imageName: String, content: String) {
        self.imageView.image = UIImage(named: imageName)
        self.contentLabel.text = content
    }
}
